#-*-makefile-*-   ; force emacs to enter makefile-mode
# ----------------------------------------------------
# Make include file for otp
#
# %CopyrightBegin%
#
# Copyright Ericsson AB 1997-2024. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# %CopyrightEnd%
#
# Author: Lars Thorsen
# ----------------------------------------------------
.SUFFIXES: .erl .beam .yrl .xrl .bin .mib .hrl .html .class .java .el .elc

# ----------------------------------------------------
#	Output
# ----------------------------------------------------
include $(ERL_TOP)/make/output.mk

# ----------------------------------------------------
#       Version
# ----------------------------------------------------

OTP_VERSION = @OTP_VERSION@
SYSTEM_VSN = @SYSTEM_VSN@

# ----------------------------------------------------
#	Cross Compiling
# ----------------------------------------------------
CROSS_COMPILING = @CROSS_COMPILING@

# ----------------------------------------------------
#	Common macros
# ----------------------------------------------------
DEFAULT_TARGETS =  opt debug release release_docs clean docs

TYPES = opt debug lcnt valgrind asan gcov
DEFAULT_TYPES = @DEFAULT_TYPES@
FLAVORS = @FLAVORS@
PRIMARY_FLAVOR= @PRIMARY_FLAVOR@

USE_PGO = @USE_PGO@

# Slash separated list of return values from $(origin VAR)
# that are untrusted - set default in this file instead.
# The list is not space separated since some return values
# contain space, and we want to use $(findstring ...) to
# search the list.
DUBIOUS_ORIGINS = /undefined/environment/

# ----------------------------------------------------
#	Command macros
# ----------------------------------------------------
INSTALL         = @INSTALL@
INSTALL_DIR     = @INSTALL_DIR@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT  = @INSTALL_SCRIPT@
INSTALL_DATA    = @INSTALL_DATA@
INSTALL_DIR_DATA = $(ERL_TOP)/make/install_dir_data.sh

CC = @CC@
GCC = @GCC@
HCC = @HCC@
CC32 = @CC32@
CXX = @CXX@
CFLAGS32 = @CFLAGS32@
BASIC_CFLAGS = @CFLAGS@
DEBUG_FLAGS =  @DEBUG_FLAGS@
LD = @LD@
RANLIB = @RANLIB@
AR = @AR@
PERL = @PERL@
LLVM_PROFDATA = @LLVM_PROFDATA@

MIXED_VC = @MIXED_VC@
MIXED_MINGW = @MIXED_MINGW@

BITS64 = @BITS64@

OTP_RELEASE = @OTP_RELEASE@

ERL_DETERMINISTIC = @ERL_DETERMINISTIC@

# ----------------------------------------------------
#	Erlang language section
# ----------------------------------------------------
EMULATOR = beam
ifeq ($(ERL_COMPILE_WARNINGS_AS_ERRORS),yes)
  ERL_COMPILE_FLAGS += -Werror
endif
ifdef PRIMARY_BOOTSTRAP
  ERL_COMPILE_FLAGS += +slim
else
  ERL_COMPILE_FLAGS += +debug_info +warn_missing_doc_function +warn_missing_doc_callback +warn_missing_spec_documented
endif
ifeq ($(ERL_DETERMINISTIC),yes)
  ERL_COMPILE_FLAGS += +deterministic
  YRL_FLAGS += +deterministic
  XRL_FLAGS += +deterministic
endif

ERLC_WFLAGS = -W
ERLC = erlc $(ERLC_WFLAGS) $(ERLC_FLAGS)
ERL = erl -boot start_clean
ESCRIPT = escript@EXEEXT@

ifneq (,$(findstring $(origin EBIN),$(DUBIOUS_ORIGINS)))
EBIN = ../ebin
endif

# Generated (non ebin) files...
ifneq (,$(findstring $(origin EGEN),$(DUBIOUS_ORIGINS)))
EGEN = .
endif

ifneq (,$(findstring $(origin ESRC),$(DUBIOUS_ORIGINS)))
ESRC = .
endif

$(EBIN)/%.beam: $(EGEN)/%.erl
	$(V_ERLC) $(ERL_COMPILE_FLAGS) -o$(EBIN) $<

$(EBIN)/%.beam: $(ESRC)/%.erl
	$(V_ERLC) $(ERL_COMPILE_FLAGS) -o$(EBIN) $<

.erl.beam:
	$(V_ERLC) $(ERL_COMPILE_FLAGS) -o$(dir $@) $<

#
# When .erl files are automatically created GNU make removes them if
# they were the result of a chain of implicit rules. To prevent this
# we say that all .erl files are "precious".
#
.PRECIOUS: %.erl %.fo

## Uncomment these lines and add .idl to suffixes above to have erlc
## eat IDL files
##$(EGEN)/%.erl: $(ESRC)/%.idl
##	$(ERLC) $(IDL_FLAGS) $<

$(EGEN)/%.erl: $(ESRC)/%.yrl
	$(yecc_verbose)$(ERLC) $(YRL_FLAGS) -o$(EGEN) $<

$(EGEN)/%.erl: $(ESRC)/%.xrl
	$(leex_verbose)$(ERLC) $(XRL_FLAGS) -o$(EGEN) $<

# ----------------------------------------------------
#	SNMP language section
# ----------------------------------------------------
SNMP_TOOLKIT = $(ERL_TOP)/lib/snmp
ifeq ($(SNMP_BIN_TARGET_DIR),)
  SNMP_BIN_TARGET_DIR = ../priv/mibs
endif
ifeq ($(SNMP_HRL_TARGET_DIR),)
  SNMP_HRL_TARGET_DIR = ../include
endif


$(SNMP_BIN_TARGET_DIR)/%.bin: %.mib
	$(snmp_verbose)$(ERLC) -pa $(SNMP_TOOLKIT)/ebin -I $(SNMP_TOOLKIT)/priv/mibs $(SNMP_FLAGS) -o $(SNMP_BIN_TARGET_DIR) $<

$(SNMP_HRL_TARGET_DIR)/%.hrl: $(SNMP_BIN_TARGET_DIR)/%.bin
	$(snmp_verbose)$(ERLC) -pa $(SNMP_TOOLKIT)/ebin -o $(SNMP_HRL_TARGET_DIR) $<

.mib.bin:
	$(snmp_verbose)$(ERLC) -pa $(SNMP_TOOLKIT)/ebin -I $(SNMP_TOOLKIT)/priv/mibs $(SNMP_FLAGS) $<

.bin.hrl:
	$(snmp_verbose)$(ERLC) -pa $(SNMP_TOOLKIT)/ebin $<

# ----------------------------------------------------
#	Java language section
# ----------------------------------------------------
JAVA= @JAVAC@

ifneq (,$(findstring $(origin JAVA_DEST_ROOT),$(DUBIOUS_ORIGINS)))
JAVA_DEST_ROOT = ../priv/
endif

.java.class:
	$(javac_verbose)CLASSPATH=$(CLASSPATH) $(JAVA) $(JAVA_OPTIONS) $<


$(JAVA_DEST_ROOT)$(JAVA_CLASS_SUBDIR)%.class: %.java
	$(javac_verbose)CLASSPATH=$(CLASSPATH) $(JAVA) $(JAVA_OPTIONS) -d $(JAVA_DEST_ROOT) $<

# ----------------------------------------------------
#	Emacs byte code compiling
# ----------------------------------------------------
EMACS_COMPILER=emacs-20
EMACS_COMPILE_OPTIONS=-q --no-site-file -batch -f batch-byte-compile

.el.elc:
	$(emacs_verbose)$(EMACS_COMPILER) $(EMACS_COMPILE_OPTIONS) $<

# ----------------------------------------------------
#	Documentation section
# ----------------------------------------------------
export VSN

EX_DOC = @EX_DOC@

DOCDIR=.
HTMLDIR = $(DOCDIR)/html
CHUNKSDIR = $(DOCDIR)/chunks

ifeq ($(HTMLLOGO),)
HTMLLOGO_FILE = erlang-logo.png
endif

CP = @CP@
MKDIR = @MKDIR@
